package com.ylkj.wx.dao.impl;

import java.util.List;

import org.hibernate.Query;
import org.springframework.stereotype.Repository;

import com.ylkj.common.base.BaseDaoHibernate;
import com.ylkj.wx.dao.EmployeeInfoDAO;
import com.ylkj.wx.dto.EmployeeInfoDTO;
import com.ylkj.wx.entitis.EmployeeEntity;

@Repository
public class EmployeeInfoDAOImlp  extends BaseDaoHibernate implements EmployeeInfoDAO {

	@Override
	public List<EmployeeInfoDTO> findEmployeeInfoList(int pageNum, int pageSize) {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public EmployeeInfoDTO fineOneEmployeeInfoById(int employeeId) {
		//biz_id
		String sql = " SELECT id AS id ,'7868768' AS empName,biz_code AS biz_code ,header_img_url AS header_img_url,phone AS phone,nick_name AS nick_name FROM employee_info WHERE id = ? ";
		Query query = this.getSession().createSQLQuery(sql);
         query.setParameter(0, employeeId);
         List<Object[]> list = query.list();
         if(list!=null && list.size()>0){
        	 Object[] object = list.get(0);
        	 EmployeeInfoDTO dto = new EmployeeInfoDTO();
        	 dto.setId((Integer) object[0]);
        	 dto.setName(object[1]==null?"":(String)object[1]);
        	
        	 dto.setBizCode( object[2]==null?"0":(String)(object[2].toString()));
        	 dto.setHeaderImgUrl(object[3]==null?"":(String)object[3]);
        	 dto.setPhone(object[4]==null?"":(String)object[4]);
        	 dto.setNickName(object[5]==null?"":(String)object[5]);
        	 return dto;
         }
		return null;
	}

	@Override
	public EmployeeEntity getEmployeeByCodeAndBizCode(String bizCode,
			String employeeCode) {
		// TODO Auto-generated method stub
		String hql="from EmployeeEntity where code=? and bizCode=?";
		List<EmployeeEntity> employeeList= this.getHibernateTemplate().find(hql, employeeCode,bizCode);
		if(employeeList==null||employeeList.isEmpty()){
			return null;
		}
		return employeeList.get(0);
	}

	@Override
	public EmployeeEntity getEmployeeById(String employeeId) {
		// TODO Auto-generated method stub
		String hql="from EmployeeEntity where phrCode=?";
		List<EmployeeEntity> employeeList= this.getHibernateTemplate().find(hql, employeeId);
		if(employeeList==null||employeeList.isEmpty()){
			return null;
		}
		return employeeList.get(0);
	}

	@Override
	public int updateQrCodeUrl(Long id, String qrCodeUrl) {
		// TODO Auto-generated method stub
		String hql="update EmployeeEntity set qrCodeUrl=? where id=?";
		return this.getHibernateTemplate().bulkUpdate(hql, id,qrCodeUrl);
	}

}
